package org.edu.model;

import java.io.Serializable;
import java.sql.Blob;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy = false)
@Table(name = "DOCUMENT", catalog="SCHOOL")
public class Document implements Serializable{

	private static final long serialVersionUID = 1L;

	private Long documnetId;
	private Set<User> users = new HashSet<>();
	private String type;
	private String subjects;
	private String filename;
	private Blob content;
	private Date date;
	private Boolean status_doc;

	@Id
	@GeneratedValue
	@Column(name = "DOCUMENTS_ID")
	public Long getDocumnetId() {
		return documnetId;
	}

	public void setDocumnetId(Long documnetId) {
		this.documnetId = documnetId;
	}

	@ManyToMany
	@JoinTable(name = "JOIN_USER_DOCUMENTS", joinColumns = { @JoinColumn(name = "DOCUMENTS_ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID") })
	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	@Column(name = "TYPE", length = 20)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Column(name = "SUBJECTS", length = 240)
	public String getSubjects() {
		return subjects;
	}

	public void setSubjects(String subjects) {
		this.subjects = subjects;
	}

	@Column(name = "FILENAME", length = 50)
	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}
	
	@Column(name = "CONTENT")
	@Lob
	public Blob getContent() {
		return content;
	}

	public void setContent(Blob content) {
		this.content = content;
	}

	@Column(name = "DATE")
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	@Column(name = "STATUS_DOC")
	public Boolean getStatus_doc() {
		return status_doc;
	}

	public void setStatus_doc(Boolean status_doc) {
		this.status_doc = status_doc;
	}
	
	public Document() {
		super();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((content == null) ? 0 : content.hashCode());
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result
				+ ((documnetId == null) ? 0 : documnetId.hashCode());
		result = prime * result
				+ ((filename == null) ? 0 : filename.hashCode());
		result = prime * result
				+ ((status_doc == null) ? 0 : status_doc.hashCode());
		result = prime * result
				+ ((subjects == null) ? 0 : subjects.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Document other = (Document) obj;
		if (content == null) {
			if (other.content != null)
				return false;
		} else if (!content.equals(other.content))
			return false;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (documnetId == null) {
			if (other.documnetId != null)
				return false;
		} else if (!documnetId.equals(other.documnetId))
			return false;
		if (filename == null) {
			if (other.filename != null)
				return false;
		} else if (!filename.equals(other.filename))
			return false;
		if (status_doc == null) {
			if (other.status_doc != null)
				return false;
		} else if (!status_doc.equals(other.status_doc))
			return false;
		if (subjects == null) {
			if (other.subjects != null)
				return false;
		} else if (!subjects.equals(other.subjects))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}
		
}
